package com.shujia.wyh.controller;

import com.shujia.wyh.entity.Emp;
import com.shujia.wyh.entity.User;
import com.shujia.wyh.service.impl.EmpServiceImpl;
import com.shujia.wyh.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("user")
public class UserController {
    //注入业务层的对象
    @Autowired
    private UserServiceImpl userService;
    @Autowired
    private EmpServiceImpl empService;


    @RequestMapping("index")
    public String index(){
        return "index";
    }

    @RequestMapping("login")
    public String showall(User user, Model model){
        User user1 = userService.findByUsernameAndPassword(user.getUsername(), user.getPassword());
        if(user1!=null){
            //如果登录成功,先查询数据库中的所有数据
            List<Emp> emps = empService.findAll();
            model.addAttribute("emps",emps);
            return "shouye";
        }else {
            System.out.println("登录失败！！");
            return "index";
        }
    }

}
